///**
// * 查看供应商提货商品验收单明细 根据传入的查询参数获取满足条件的记录
// *
// * @param client
// * @param config
// * @param bodyJSObj
// * @return
// */
//public Future<JsonObject> getRecordsForPickupGoodsInspectAccept(PgPool client, JsonObject config, JsonObject bodyJSObj) {
//Promise<JsonObject> promise = Promise.promise();
////最后返回的JsonObject对象
//JsonObject responseJSObj = new JsonObject();
//// 验证必须传的数值字段
//List<String> numeric_fields = Arrays.asList("warehouse_id", "aggregation_id", "page_size", "page_index");
//JsonObject numeric = this.commonRepository.verifyAllParamNumeric(bodyJSObj, numeric_fields);
//if (numeric != null) {
//promise.complete(numeric);
//return promise.future();
//}
//
////从bodyJson中获取数据   各字段注释请参看数据库设计文档中数据表supplier_goods_profit_loss的说明\
//String warehouse_id = bodyJSObj.getString("warehouse_id");
//String aggregation_id = bodyJSObj.getString("aggregation_id");
//
//int page_size = Integer.valueOf(bodyJSObj.getString("page_size"));
//int page_index = Integer.valueOf(bodyJSObj.getString("page_index"));
//int query_offset = (page_index - 1) * page_size;
//int query_limit = page_size;
////用于传递给构建sql的JsonObject
//JsonObject queryJSObj = new JsonObject();
//
////定义多个set，存储每一个 initial_batch_detail 中多个code
//Set<String> warehouse_id_list_set = new HashSet<String>();
//Set<String> supply_chain_goods_id_list_set = new HashSet<String>();
//
//queryJSObj.put("warehouse_id", warehouse_id);
//queryJSObj.put("aggregation_id", aggregation_id);
//this.commonRepository.getCon(client).onSuccess(conn -> {
////先获取供应商商品供应商提货商品验收单
//String sql = createSelectSqlForSupplierPickupGoodsInspectAccept(queryJSObj, query_offset, query_limit);
//this.commonRepository.queryJsonArray(conn, sql, "getSupplierPickupGoodsInspectAcceptRecords")
//.onSuccess(resJSArray1 -> { //resJSArray中就是获取到符合条件的数据
////        取出每条记录中含code字段的值放入对应的集合
//for (int i = 0; i < resJSArray1.size(); i++) {
//JsonObject jsonObj = resJSArray1.getJsonObject(i);
//warehouse_id_list_set.add(jsonObj.getString("warehouse_id"));
//supply_chain_goods_id_list_set.add(jsonObj.getString("supply_chain_goods_id"));
//}
////在获取销售地区供应商商品供应商提货商品验收单
//String sql2 = createSelectSqlForSalesSupplierPickupGoodsInspectAccept(queryJSObj, query_offset, query_limit);
//this.commonRepository.queryJsonArray(conn, sql2, "getSalesSupplierPickupGoodsInspectAcceptRecords")
//.onSuccess(resJSArray2 -> { //resJSArray中就是获取到符合条件的数据
////        取出每条记录中含code字段的值放入对应的集合
//for (int i = 0; i < resJSArray2.size(); i++) {
//JsonObject jsonObj = resJSArray2.getJsonObject(i);
//warehouse_id_list_set.add(jsonObj.getString("warehouse_id"));
//supply_chain_goods_id_list_set.add(jsonObj.getString("supply_chain_goods_id"));
//}
////获取满足条件的记录总数
//String count_sql = this.commonRepository.createCountSql(queryJSObj, "supplier_goods_profit_loss");
//Future<Integer> getTotalFuture = this.commonRepository.getRecordsCount(conn, count_sql, "get_supplier_goods_profit_loss");
//String count_sql2 = this.commonRepository.createCountSql(queryJSObj, "sales_supplier_goods_profit_loss");
//Future<Integer> getTotalFuture2 = this.commonRepository.getRecordsCount(conn, count_sql, "get_supplier_goods_profit_loss");
////获取仓库编码和名称
//String warehouse_sql = "select distinct id, warehouse_name from  warehouse where id = any(array[" +
//String.join(",", warehouse_id_list_set) + "])";
//Future<JsonObject> getWarehouseFuture = this.commonRepository.getCodeNamePairJsonObject(conn, warehouse_sql, "get_warehouse_name");
////获取供应链商品编码和名称
//String supply_chain_goods_sql = "select distinct id, supply_chain_goods_name from  supply_chain_goods where id = any(array[" +
//String.join(",", supply_chain_goods_id_list_set) + "])";
//Future<JsonObject> getSupplyChainGoodsFuture = this.commonRepository.getCodeNamePairJsonObject(conn, supply_chain_goods_sql, "get_supply_chain_goods_name");
//
//
//CompositeFuture.join(Arrays.asList(getTotalFuture,getTotalFuture2, getWarehouseFuture, getSupplyChainGoodsFuture)).onComplete(ar2 -> {
//if (ar2.succeeded()) {
//int total_records = Integer.valueOf(ar2.result().list().get(0).toString()) + Integer.valueOf(ar2.result().list().get(1).toString());
//JsonObject warehouse_info = new JsonObject();
//JsonObject supply_chain_goods_info = new JsonObject();
//
//warehouse_info = (JsonObject) ar2.result().list().get(2);
//supply_chain_goods_info = (JsonObject) ar2.result().list().get(3);
//// 最后组装含有name的Json对象和数组
//JsonArray recordsJSArray = new JsonArray();
//for (int i = 0; i < resJSArray1.size(); i++) {
//JsonObject record_obj = resJSArray1.getJsonObject(i);
//record_obj.put("warehouse_name", warehouse_info.getString(record_obj.getString("warehouse_id")));
//record_obj.put("supply_chain_goods_name", supply_chain_goods_info.getString(record_obj.getString("supply_chain_goods_id")));
//recordsJSArray.add(record_obj);
//}
//for (int i = 0; i < resJSArray2.size(); i++) {
//JsonObject record_obj = resJSArray2.getJsonObject(i);
//record_obj.put("warehouse_name", warehouse_info.getString(record_obj.getString("warehouse_id")));
//record_obj.put("supply_chain_goods_name", supply_chain_goods_info.getString(record_obj.getString("supply_chain_goods_id")));
//recordsJSArray.add(record_obj);
//}
//JsonObject dataJSObj = new JsonObject();
//dataJSObj.put("total", total_records).put("records", recordsJSArray);
//responseJSObj.put("id", 0).put("msg", "获取记录成功").put("data", dataJSObj);
//promise.complete(responseJSObj);
//} else {
//logger.info("获取记录数据发生错误: {}", ar2.cause().getMessage());
//promise.complete(CommonUtils.createExceptionJsonObject(ar2, "getPickupGoodsInspectAcceptRecords", "获取供应商提货商品验收单明细参数失败"));
//}
//});
//}).onFailure(err -> promise.complete(CommonUtils.createExceptionJsonObject(err, "getPickupGoodsInspectAcceptRecords", "获取销售地区供应商商品供应商提货商品验收单明细参数失败")));
//}).onFailure(err -> promise.complete(CommonUtils.createExceptionJsonObject(err, "getPickupGoodsInspectAcceptRecords", "获取供应商商品供应商提货商品验收单明细参数失败")));
//}).onFailure(err -> promise.fail(CommonUtils.createJsonObject(err, "getPickupGoodsInspectAcceptRecords", "数据库连接失败")));
//return promise.future();
//}
//
///**
// * 创建查询符合搜索条件记录的sql语句——查看供应商提货商品验收单明细
// *
// * @param queryJS      body参数对象
// * @param query_offset 页面偏移
// * @param query_limit  页面记录数
// * @return 查询符合搜索条件的sql语句
// */
//public String createSelectSqlForSupplierPickupGoodsInspectAccept(JsonObject queryJS, int query_offset, int query_limit) {
//SelectQuery sq = new SelectQuery();
//sq.addCustomColumns(new CustomSql("id"), new CustomSql("supplier_pickup_goods_inspect_accept_id"), new CustomSql("supply_chain_goods_id"),new CustomSql("goods_batch_code"),
//new CustomSql("total_weight"), new CustomSql("total_number"), new CustomSql("prepare_pickup_plan_price_bid_id"),
//new CustomSql("is_delete"), new CustomSql("create_user"), new CustomSql("update_user"), new CustomSql("create_time"), new CustomSql("update_time"))
//.addCustomFromTable("supplier_pickup_goods_inspect_accept_detail");
//Iterator<String> iter = queryJS.fieldNames().iterator();
//while (iter.hasNext()) {
//String key = iter.next();
//try {
//String value = queryJS.getString(key);
//if (!value.equals("") && !value.equals("[]") && !value.equals("[all]")) {
//String firstChar = value.substring(0, 1);
//if (firstChar.equals("["))
//value = value.substring(1, value.length() - 1);
//value = value.replace(", ", "','");
//// 添加where  InCondtion 子句
//sq.getWhereClause().addCustomCondition(new InCondition(new CustomSql(key), value));
//}
//} catch (Exception e) {
//logger.info("createSql, 发生错误,错误原因: ", e.getMessage());
//}
//}
//return sq.validate() + " order by id desc limit " + query_limit + " offset " + query_offset;
//}
//
///**
// * 创建查询符合搜索条件记录的sql语句——查看销售地区供应商商品供应商提货商品验收单明细
// *
// * @param queryJS      body参数对象
// * @param query_offset 页面偏移
// * @param query_limit  页面记录数
// * @return 查询符合搜索条件的sql语句
// */
//public String createSelectSqlForSalesSupplierPickupGoodsInspectAccept(JsonObject queryJS, int query_offset, int query_limit) {
//SelectQuery sq = new SelectQuery();
//sq.addCustomColumns(new CustomSql("id"), new CustomSql("supplier_pickup_goods_inspect_accept_id"), new CustomSql("supply_chain_goods_id"),new CustomSql("goods_batch_code"),
//new CustomSql("total_weight"), new CustomSql("total_number"), new CustomSql("sales_pickup_plan_command_id"),
//new CustomSql("is_delete"), new CustomSql("create_user"), new CustomSql("update_user"), new CustomSql("create_time"), new CustomSql("update_time"))
//.addCustomFromTable("sales_supplier_pickup_goods_inspect_accept_detail");
//Iterator<String> iter = queryJS.fieldNames().iterator();
//while (iter.hasNext()) {
//String key = iter.next();
//try {
//String value = queryJS.getString(key);
//if (!value.equals("") && !value.equals("[]") && !value.equals("[all]")) {
//String firstChar = value.substring(0, 1);
//if (firstChar.equals("["))
//value = value.substring(1, value.length() - 1);
//value = value.replace(", ", "','");
//// 添加where  InCondtion 子句
//sq.getWhereClause().addCustomCondition(new InCondition(new CustomSql(key), value));
//}
//} catch (Exception e) {
//logger.info("createSql, 发生错误,错误原因: ", e.getMessage());
//}
//}
//return sq.validate() + " order by id desc limit " + query_limit + " offset " + query_offset;
//}